from server import vfs
from server.userobj import User
import os


class Checker():  # 权限检测
    def __init__(self, plugid: str):
        self.plugid = plugid

    # 功能权限检测
    async def check_func_permission(self, user: User, level: int = 1, func_name: str | None = None) -> bool:
        if (func_name is None or func_name == ""):
            check_path = f"//plugin/{self.plugid}"
        else:
            check_path = f"//plugin/{self.plugid}/{func_name}"
        return await vfs.check_permission(user.username, check_path, level)

    # 路径权限检测
    async def check_path_permission(self, user: User, path: str, level: int = 1, resursive: bool = False) -> bool:
        return await vfs.check_permission(user.username, os.path.abspath(path), level, rescursive=resursive)
